﻿using System.Net.Http;

namespace User.Api.Helpers
{
    public class AzUser
    {
        /// <summary>
        /// 用户表的ID
        /// </summary>
        public long UserId { get; set; }

        /// <summary>
        /// OpenId
        /// </summary>
        public string OpenId { get; set; }

        public static void SetInApi(HttpRequestMessage request, long userId, string openId)
        {
            var azUser = new AzUser
            {
                UserId = userId,
                OpenId = openId
            };

            request.Properties["AzUser"] = azUser;
        }

        public static AzUser GetInApi(HttpRequestMessage request)
        {
            if (!request.Properties.ContainsKey("AzUser"))
            {
                return null;
            }

            var azUser = (AzUser)request.Properties["AzUser"];

            return azUser;
        }
    }
}